2 Problem: 924 - Spreading the news (UVa Online Judge)
3 Andrés Mejía-Posada (http://github.com/andmej/acm)
6 Algorithm: Breadth-first search
19 for (int i
=0; i
<E
; ++i
){
34 if (g
[start
].size() == 0){
37 int max_boom
= -1, first_day
= -1, booms
[E
];
39 memset(booms
, 0, sizeof booms
);
40 memset(visited
, false, sizeof visited
);
41 queue
<pair
<int, int> > q
;
42 q
.push(make_pair(start
, 0));
44 int person
= q
.front().first
;
45 int today
= q
.front().second
;
48 if (visited
[person
]) continue;
50 visited
[person
] = true;
52 if (today
> 0 && booms
[today
] > max_boom
){
53 max_boom
= booms
[today
];
57 vector
<int> &friends
= g
[person
];
58 for (int i
=0; i
<friends
.size(); ++i
){
59 if (!visited
[friends
[i
]]){
60 q
.push(make_pair(friends
[i
], today
+ 1));
64 assert(max_boom
!= -1 && first_day
!= -1);
65 printf("%d %d\n", max_boom
, first_day
);